package com.qianfeng.smsplatform.search.mq;


//
//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖镇楼            BUG辟易  
//          佛曰:  
//                  写字楼里写字间，写字间里程序员；  
//                  程序人员写程序，又拿程序换酒钱。  
//                  酒醒只在网上坐，酒醉还来网下眠；  
//                  酒醉酒醒日复日，网上网下年复年。  
//                  但愿老死电脑间，不愿鞠躬老板前；  
//                  奔驰宝马贵者趣，公交自行程序员。  
//                  别人笑我忒疯癫，我笑自己命太贱；  


import com.fasterxml.jackson.databind.ObjectMapper;
import com.qianfeng.smsplatform.common.constants.RabbitMqConsants;
import com.qianfeng.smsplatform.common.model.Standard_Report;
import com.qianfeng.smsplatform.common.model.Standard_Submit;
import com.qianfeng.smsplatform.search.service.SearchService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by jackiechan on 2021/4/7 21:43
 *
 * @author jackiechan
 */
@Component
public class ReceiveSubmitFromMQ {
    static final Logger LOGGER = LoggerFactory.getLogger(ReceiveSubmitFromMQ.class);
//    @Autowired
    //private ElasticSearchCRUDRep elasticSearchCRUDRep;
    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private SearchService searchService;

    @RabbitListener(queues = RabbitMqConsants.TOPIC_SMS_SEND_LOG,containerFactory = "containerFactory")
    public void receiveSubmit(Standard_Submit standard_submit) {

     try {
         LOGGER.error("收到发送短信成功的消息:{}", standard_submit);
//         Submit_ES submit_es = new Submit_ES();
//         submit_es.setLongCode(standard_submit.getSrcNumber());
//         submit_es.setSmsContent(standard_submit.getMessageContent());
       //  elasticSearchCRUDRep.save(submit_es);
         String json = objectMapper.writeValueAsString(standard_submit);
         searchService.add(json);
     }catch (Exception e){
        e.printStackTrace();
     }
    }

    @RabbitListener(queues = RabbitMqConsants.TOPIC_UPDATE_SMS_REPORT,containerFactory = "containerFactory")
    public void onUpdateReport(Standard_Report report) {
        LOGGER.error("收到更新短信状态的消息:{}", report);
        try {
            searchService.update(report);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
